With
.NET, Web services were originally developed using ASP.NET together
with IIS. ASP.NET provided an extensive framework built on top of the
CLR for developing both Web services and general Web sites.
XML Web Services (ASMX)
Web
services were officially referred to as “XML Web Services” and were
further termed with the ASMX acronym because, when developed with
ASP.NET, their logic was placed into a file with the .asmx extension.
Specifically, this file contained:
The typical implementation for a Web service was contained in a code-behind file that is actually referenced using the @WebService directive, as follows:
Example 1.
<% @WebService Language="C#" CodeBehind="~/App_Code/DemoService.cs" Class="DemoService" %>
|
The .NET API used to implement a Web service was contained in the System.Web.Services namespace. Classes and attributes from the namespace used to implement the Web service included:
WebService attribute
WebMethod attribute
Let’s briefly explain each.
The WebService Attribute
This attribute has to be applied to a class in order to designate it as a Web service, as follows:
Example 2.
using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; [WebService(Description = "Demo Service", Namespace = "http://www.example.org")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] interface IDemoService { string Greet(); } public class DemoService : System.Web.Services.WebService, IDemoService { [WebMethod] public string Greet() { return "Hello World"; } }
|
In
this example, the Web service was defined using a .NET interface
definition, thereby decoupling the service definition from the service
contract (which, incidentally, makes the service easier to manage,
reuse, and migrate to WCF).
The WebService attribute accepted three parameters, as shown in Table 1.
Table 1. The parameters for the WebService attribute.
Parameter | Description |
---|
Description | a brief description of the Web service to help a human user understand its purpose |
Name | the name of the Web service (included in the WSDL file and used by service consumers to target the service) |
Namespace | the XML namespace for the Web service |
The WebMethod Attribute
The WebMethod
attribute was used to tag operations in a class that could be exposed
by a Web service. For an operation to be available to the service
consumer it had to be a public method and further had to be annotated
with a WebMethod attribute, as was shown in Example 2.
The WebMethod attribute contained optional parameters that could be used to customize each operation, as listed in Table 2.
Table 2. The parameters for the WebMethod attribute.
Parameter | Description |
---|
BufferResponse | when BufferResponse is set to true, ASP.NET buffers the entire response before sending it to the client—a very efficient, default setting |
CacheDuration | enables
caching the results of a Web service operation (ASP.NET will cache
results for a unique set of parameters for the specified duration of
time) |
Description | used to describe an operation for a human user to comprehend the Web method |
EnableSession | used to enable session state for a Web method |
MessageName | used to uniquely identify overloaded methods using an alias (default value is the name of the method) |
TransactionOption | enables a Web method to participate in a transaction (disabled by default) |
Web Service Enhancements (WSE)
ASMX primarily supported
the creation of Web services based on SOAP and WSDL. It originally did
not include support for other WS-* industry standards, most notably
WS-Security.
Microsoft subsequently
released Web Services Enhancements (WSE) as an extension for the
initial ASMX platform. WSE added support for various WS-* standards
that introduced new features, such as message-layer security,
content-based routing, and support for policies (which corresponded to
the WS-Security, WS-Addressing, and WS-Policy standards respectively).